﻿<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>
					<xsl:value-of select="xbel/title" />
				</title>
			</head>

			<body>
				<div class="xbel">
					<div class="title">
						<xsl:value-of select="xbel/title" />
					</div>
					<div class="content">
						<xsl:for-each select="xbel/folder | xbel/bookmark">
							<xsl:choose>
								<xsl:when test="local-name(.)='folder'">
									<xsl:call-template name="displayFolder" />
								</xsl:when>
								<xsl:when test="local-name(.)='bookmark'">
									<xsl:call-template name="displayBookmark" />
								</xsl:when>
							</xsl:choose>
						</xsl:for-each>
					</div>
					<!--p class="footer">Generated from an XBEL compliant file through xbel2html.xsl</p-->
				</div>
			</body>
		</html>
	</xsl:template>

	<xsl:template name="displayFolder" match="folder">
		<div class="folder">
			<div class="title">
				<xsl:element name="img">
					<xsl:attribute name="src">bookmark_folder.png</xsl:attribute>			
				</xsl:element>
				<xsl:element name="a">
					<xsl:attribute name="href">#</xsl:attribute>
					<xsl:attribute name="onclick">javascript:_toggle(_gel('content_<xsl:value-of select="generate-id(.)" />'));</xsl:attribute>
					<xsl:value-of select="./title" />
				</xsl:element>
			</div>
			<div class="content" style="display: none;">
				<xsl:attribute name="id">content_<xsl:value-of select="generate-id(.)" /></xsl:attribute>
				<xsl:for-each select="./folder" >
					<xsl:call-template name="displayFolder" />
				</xsl:for-each>
				<xsl:for-each select="./bookmark" >
					<xsl:call-template name="displayBookmark" />
				</xsl:for-each>
			</div>
		</div>
	</xsl:template>

	<xsl:template name="displayBookmark" match="bookmark">
		<div class="bookmark">
			<xsl:choose>
				<xsl:when test="./info/metadata/@Icon!=''">
					<xsl:element name="img">
						<xsl:attribute name="src">
							<xsl:value-of select="./info/metadata/@Icon" />
							</xsl:attribute>			
					</xsl:element>
				</xsl:when>
				<xsl:otherwise>
					<xsl:element name="img">
						<xsl:attribute name="src">bookmark.png</xsl:attribute>			
					</xsl:element>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:element name="a">
				<xsl:attribute name="href">
					<xsl:value-of select="./@href" />
				</xsl:attribute>
				<xsl:attribute name="title">
					<xsl:value-of select="./@href" />
				</xsl:attribute>
				<xsl:attribute name="target">_blank</xsl:attribute>
				<xsl:value-of select="./title" />
			</xsl:element>
			<xsl:choose>
				<xsl:when test="./desc">
					<xsl:element name="div">
						<xsl:attribute name="class">description</xsl:attribute>
						<xsl:value-of select="./desc" />
					</xsl:element>
				</xsl:when>
			</xsl:choose>
		</div>
	</xsl:template>

</xsl:stylesheet>
